package com.ty.consumer;

import com.ty.dto.Invertory;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageConsumer1 {


    @Bean
    public Queue Q1() {
        return QueueBuilder.durable("不做操作").build();
    }

    @Bean
    public Queue Q2() {
        return QueueBuilder.durable("用户下单").build();
    }

    @Bean
    public Queue Q3() {
        return QueueBuilder.durable("订单完成").build();
    }

    @Bean
    public TopicExchange exchange(){
        return ExchangeBuilder.topicExchange("exchange.topic").durable(true).build();
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(Q1()).to(exchange()).with("0");
    }

    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(Q2()).to(exchange()).with("90");
    }

    @Bean
    public Binding binding3(){
        return BindingBuilder.bind(Q3()).to(exchange()).with("100");
    }

    @RabbitListener( queues = "0")

    public void  consumer1(Invertory msg){
        System.out.println("不执行任何操作...");
    }

    @RabbitListener( queues = "90")
    public void  consumer2(Invertory msg){
        System.out.println("用户下单,销量增加");
    }

    @RabbitListener( queues = "100")
    public void  consumer3(Invertory msg){
        System.out.println("订单完成,库存扣减");
    }

}
